#include "sha1.h"
#include <stdio.h>
#include <openssl/sha.h>

void calculateHash(unsigned char result[SHA_DIGEST_LENGTH], char *message)
{
    SHA_CTX c;

    SHA1_Init(&c);
    SHA1_Update(&c, message, strlen(message));
    SHA1_Final(result, &c);
}

void
calculateSha1(char * name, char * key, unsigned char dest[AESKEYLENGTH])
{
	unsigned char sha1[SHA_DIGEST_LENGTH];
	char strAux[MAXNAMELENGTH + MAXKEYLENGTH + 1];

	strcpy(strAux, name);
	strcat(strAux, key);

	calculateHash(sha1, strAux);

	memcpy(dest, sha1, AESKEYLENGTH);
}
